package com.hq.door.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	
	public final static String ymdHms = "yyyy-MM-dd HH:mm:ss";
	public static final String ymdhms = "yyyy-MM-dd hh:mm:ss";
	public static final String y = "yyyy";
	public static final String ym = "yyyy-MM";
	public static final String ymd = "yyyy-MM-dd";
	public static final String Hms = "HH:mm:ss";
	public static final String hms = "HH:mm:ss";
	
	public static String time2Str(Long l,String format){
		if(l==null||l==0l){
			return "";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(new Date(l));
	}
	
	/**
	 * 字符串转日期
	 * @param str		字符串
	 * @param format	转换格式
	 * @return
	 */
	public static Date str2Date(String str,String format){
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date date = null;
		try {
			if(str!=null&&!str.equals("")){
				System.out.println(str);
				date = sdf.parse(str);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return date;
	}
	
}
